<template>
  <div class="index-container">
    <RayTable ref="table" :menu="menu" data_object_no="form_making" :height="tableHeight" :is_permission="false">
      <template #form_append={form}>
        <el-row :gutter="4">
          <el-col :span="24">
            <el-form-item label="表单" prop="json" label-width="120px">
              <el-input v-model="form.json" v-show="false"></el-input>
              <el-button type="primary" @click="designForm(form)">进入设计</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
    </RayTable>
    <vxe-modal id="form_making" v-model="show" :destroy-on-close="true" :fullscreen="true">
      <template #title>
        <span>表单设计</span>
      </template>
      <template #default>
        <fm-making-form ref="makingform" preview>
          <template slot="action">
            <el-button type="text" icon="el-icon-upload" @click="formSave">保存返回上一步</el-button>
          </template>
        </fm-making-form>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
  import RayTable from '@/views/template/components/rayTable.vue'
  import '@/components/form-making/dist/FormMaking.umd.min.js'

  export default {
    name: 'form',
    components: {
      RayTable
    },
    data() {
      return {
        show: false,
        form: {}
      }
    },
    created() {
      this.menu = {}
      this.tableHeight = document.documentElement.clientHeight - 250
    },
    methods: {
      designForm(form) {
        this.form = form
        this.show = true
        this.$nextTick(() => {
          this.$refs.makingform.setJSON(JSON.parse(form.json))
        })
      },
      formSave() {
        this.$confirm('确认保存该表单并进行下一步吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$set(this.form, 'json', JSON.stringify(this.$refs.makingform.getJSON()))
          this.show = false;
        })

      },
    }
  }
</script>

<style></style>
